package liumengbaio.lolzhangyoubao.Activity.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import de.hdodenhof.circleimageview.CircleImageView;
import liumengbaio.lolzhangyoubao.Activity.InFo.ComentInfoUp;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/15.
 */
public class ComentItemAdapter extends BaseAdapter {
    private Context mContext;
    private ComentInfoUp comentInfoUp;

    public ComentItemAdapter(Context mContext, ComentInfoUp comentInfoUp) {
        this.mContext = mContext;
        this.comentInfoUp = comentInfoUp;
    }

    @Override
    public int getCount() {
        return comentInfoUp.getData().size();
    }

    @Override
    public Object getItem(int position) {
        return comentInfoUp.getData().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolderComentitem holder = null;
        if (holder == null) {
            holder=new ViewHolderComentitem();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.coment_item_activity, null);
            holder.head_icon = (CircleImageView) convertView.findViewById(R.id.head_icon);
            holder.comment_nicker_name = (TextView) convertView.findViewById(R.id.comment_nicker_name);
            holder.comment_time = (TextView) convertView.findViewById(R.id.comment_time);
            holder.comment_content = (TextView) convertView.findViewById(R.id.comment_content);
            holder.tv_number = (TextView) convertView.findViewById(R.id.tv_number);
        } else {
            holder = (ViewHolderComentitem) convertView.getTag();
        }
        Picasso.with(mContext).load(comentInfoUp.getData().get(position).getUser_avatar()).into(holder.head_icon);
        holder.comment_content.setText(comentInfoUp.getData().get(position).getContent());
        holder.comment_nicker_name.setText(comentInfoUp.getData().get(position).getNickname());
        holder.comment_time.setText(comentInfoUp.getData().get(position).getCreated());
        holder.tv_number.setText(comentInfoUp.getData().get(position).getGood());
        return convertView;
    }

    public class ViewHolderComentitem {
        private CircleImageView head_icon;
        private TextView comment_nicker_name, comment_time, comment_content, tv_number;
    }
}
